package com.wzy.event;

import com.alibaba.fastjson.JSONObject;
import com.wzy.domain.entity.Event;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * 消息生产
 *
 * @author ultima
 * @version 2022/10/26 19:37
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class EventProducer
{
    private final KafkaTemplate<String, String> kafkaTemplate;

    // 处理事件
    public void fireEvent(Event event)
    {
        if (!event.getUserId().equals(event.getEntityUserId()))
        {
            kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
        }
    }

}
